﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RemoteTestRunner.UnitTesting;

namespace RemoteTestRunnerDemo
{
    [TestClass]
    public class CompleteDemo
    {
        private static MultiAssertTestClassHelper _testClassHelper;
        public TestContext TestContext { get; set; }

        [ClassInitialize]
        public static void MyClassInitialize(TestContext testContext)
        {
            _testClassHelper =
                new MultiAssertTestClassHelper("CompletedDemo", testContext);
        }

        [ClassCleanup]
        public static void MyClassCleanup()
        {
            _testClassHelper.Dispose();
        }

        [TestMethod]
        [DeploymentItem("RemoteTestRunnerDemo\\DemoData.xls")]
        [DataSource("DemoDataSource")]
        public void TestMethod0()
        {
            TestContext.WriteLine("Input1: {0}",
                                  TestContext.DataRow["Input1"].ToString());

            Assert.IsFalse(string.IsNullOrEmpty(TestContext.DataRow["Input1"].ToString()));
        }

        [TestMethod]
        [DeploymentItem("RemoteTestRunnerDemo\\DemoData.xls")]
        [DataSource("DemoDataSource")]
        public void TestMethod1()
        {
            using (var functionHelper =
                _testClassHelper.GetFunctionHelper(TestContext))
            {
                functionHelper
                    .AddInput("Input1")
                    .AddInput("Input2", TestContext.DataRow["Input2"]);

                var input1 = functionHelper.FieldValue<int>("Input1");
                var input2 = Convert.ToInt32(TestContext.DataRow["input2"]);

                var result = input1 + input2;

                //functionHelper.AreEqual<int>(TestContext.DataRow["Output1"], result, "Sum of ints", "Output1");
                functionHelper.AreEqual(result, "Sum of ints", "Output1");
            }
        }

        [TestMethod]
        [DeploymentItem("RemoteTestRunnerDemo\\DemoData.xls")]
        [DataSource("DemoDataSource")]
        public void TestMethod11()
        {
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))
            {
                functionHelper
                    .AddInput("Input1")
                    .AddInput("Input2", TestContext.DataRow["Input2"]);

                var input1 = functionHelper.FieldValue<int>("Input1");
                var input2 = Convert.ToInt32(TestContext.DataRow["input2"]);

                var result = input1 + input2;

                functionHelper.AreEqual(result, "Sum of ints", "Output1");
            }
        }
    }
}